package transaction_date

import (
	"adam2/internal/properties"
	"anubis-framework/pkg/io"
	"gorm.io/gorm"
)

// 多个交易日期
type ManyTransactionDate struct {
	db *gorm.DB
}

// 初始化
func (m *ManyTransactionDate) Init(db *gorm.DB) {
	m.db = db
}

// 查询交易日期数组，并按日期升序排列
func (m *ManyTransactionDate) DoTransactionDate() []string {
	io.Infoln("查询交易日期数组，并按日期升序排列，开始时间为[%s]，结束时间为[%s]",
		properties.QuantProperties_.BeginDate, properties.QuantProperties_.EndDate)

	var dateArray []string
	m.db.Raw("select distinct to_char(t.date_, 'yyyy-mm-dd') from stock_transaction_data_all t "+
		"where t.date_ between to_date(?, 'yyyy-mm-dd') and to_date(?, 'yyyy-mm-dd') "+
		"order by to_char(t.date_, 'yyyy-mm-dd') asc", properties.QuantProperties_.BeginDate, properties.QuantProperties_.EndDate).
		Scan(&dateArray)
	return dateArray
}

